import Vue from 'vue'
const utils = {
	goBack(delta = 1){
		history.go(-1)
		// uni.navigateBack({
		//     delta: delta
		// });
	},
	goPath(path = '', data = {},type = 'navigateTo'){
		uni[type]({
		    url: this.setUrl(path,data)
		});
	},
	setUrl(url,obj){
	  let uri = Object.keys(obj).map(v => `&${v}=${obj[v]}`).join('').slice(1);
	  if(!url)url='';
	  return `${url}?${uri}`
	},
	CheckPassWord(password) {//必须为字母加数字且长度不小于8位
	   var str = password;
	    if (str == null || str.length <6) {
	        return false;
	    }
	    var reg1 = new RegExp(/^[0-9A-Za-z]+$/);
	    if (!reg1.test(str)) {
	        return false;
	    }
	    var reg = new RegExp(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$/);
	    if (reg.test(str)) {
	        return true;
	    } else {
	        return false;
	    }
	},
	rules:{
		idcard: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
	},
	//通过身份证号计算年龄、性别、出生日期
	idCard(userCard, num) {
	//获取出生日期
		var birth ;
	    if (num == 1) {
	        birth = userCard.substring(6, 10) + "-" + userCard.substring(10, 12) + "-" + userCard.substring(12, 14);
	        return birth;
	    }
	//获取性别
	    if (num == 2) {
	        if (parseInt(userCard.substr(16, 1)) % 2 == 1) {
	            return "男";
	        } else {
	            return "女";
	        }
	    }
	//获取年龄
	    if (num == 3) {
	        var myDate = new Date();
	        var month = myDate.getMonth() + 1;
	        var day = myDate.getDate();
	        var age = myDate.getFullYear() - userCard.substring(6, 10) - 1;
	        if (userCard.substring(10, 12) < month || userCard.substring(10, 12) == month && userCard.substring(12, 14) <= day) {
	            age++;
	        }
	        return age;
	    }
	}
}
export default utils
Vue.prototype.utils = utils